package com.winchain.provider.expiration.cmd;

import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.base.po.CbOpt;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.base.service.CbDctService;
import com.winchain.chainbill.bill.base.service.CbSndService;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.discount.service.impl.BillDctFinQuotaService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillExpResDctFinQuotaCmd implements ICommand<Bill<CbRec>> {
	@Autowired
	private CbSndService cbSndService;
	@Autowired
	private BillDctFinQuotaService billDctFinQuotaService;
	@Autowired
	private CbDctService cbDctService;

	public boolean execute(CommandContext<Bill<CbRec>> context) throws Exception {
		Bill<CbRec> bill = (Bill) context.getSource();
		CbOpt operation = (CbOpt) context.getValue("Operation");
		CbRec rec = bill.getRec();
		String curState = operation.getCurState();
		if (("S011".equals(curState)) || ("S012".equals(curState)) || ("S035".equals(curState))) {
			CbSnd snd = this.cbSndService.getBillSndById(rec.getRootId());
			List<String> dctStates = new ArrayList();
			dctStates.add("1");
			dctStates.add("2");
			CbDct dct = this.cbDctService.selectDctByBillIdAndStates(rec.getBillId(), dctStates);
			this.billDctFinQuotaService.trade(rec, snd, dct, "qt_res", "����������������");
		}
		return false;
	}
}
